package fr.ants.controller.command;

import fr.ants.view.panel.SimulationPanel;

/**
 * Apply the modification on the simulation.
 */
public class ApplySimulationCommand implements Command {

	/**
	 * to have the parameter of the simulation.
	 */
	private final SimulationPanel simulationPanel;

	/**
	 * Build.
	 * 
	 * @param simulationPanel
	 *            to have the parameter of the simulation.
	 */
	public ApplySimulationCommand(final SimulationPanel simulationPanel) {
		this.simulationPanel = simulationPanel;
	}

	@Override
	public void execute() {
		if (simulationPanel.getNode().getResource() != null) {
			simulationPanel.getNode().getResource()
					.setCapacity(simulationPanel.getCapacityValue());
			simulationPanel.getNode().getResource()
					.setRegenRate(simulationPanel.getSpeedValue());
			simulationPanel.getNode().getResource().reset();
		}
		simulationPanel.getNode().setDifficulty(
				simulationPanel.getDifficultyValue());
		simulationPanel.setNode(null);
		simulationPanel.setEnabledButtonApply(false);
	}

}
